var windowName = "myAuth";
var Page,pic1,pic2,pic3;
apiready = function(){
    pic1 = new PicUp();
    pic2 = new PicUp();
    pic3 = new PicUp();
    onWindowShow(function () {
        console.log(windowName + " show")
    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        name:""
        ,code:""
        ,pic1:""
        ,pic2:""
        ,pic3:""

        ,log:[]
    },{
        //页面方法
        "init":function () {
            this.log = getLocData("myAuth");
            apiGet("/api/userAuths", {}, function (res , code) {
                logJson(res,"/api/userAuths_Get")
                if (code == 200) {
                    Page.log = res.data;
                    // showToast(res.message)
                    setLocData("myAuth",res.data)
                }else {
                    showToast("系统繁忙")
                }
            });

            var _this = this;
            pic1.setCbFunc(function (pics) {
                if (pic1.getData()) {
                    _this.pic1 = pic1.getData()[0];
                }
            })
            var _this = this;
            pic2.setCbFunc(function (pics) {
                if (pic2.getData()) {
                    _this.pic2 = pic2.getData()[0];
                }
            })
        }
        , submit: function () {
            if (!isTrue(this.name)){showToast("请输入姓名");return}
            if (!isTrue(this.code)){showToast("请输入身份证号");return}
            if (!isTrue(this.pic1)){showToast("请上传身份证正面照片");return}
            if (!isTrue(this.pic2)){showToast("请上传身份证背面照片");return}
            var data = {
                name:this.name,
                code:this.code,
                pic1:this.pic1,
                pic2:this.pic2,
            }
            apiPost("/api/userAuths",data,function (res , code) {
                Page.init();
                showToast(res.message);
            })
        }
        ,selectPic1:function () {
            pic1.uploadedPath = [];
            pic1.chooseSrc(1)
        }
        ,selectPic2:function () {
            pic2.uploadedPath = [];
            pic2.chooseSrc(1)
        }
    })
    Page.init()
}
